-
Notifications
You must be signed in to change notification settings - Fork 27
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: unsynchronized concurrent wasm calls #1155
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
@@ -73,7 +85,7 @@ function Home() { | |||
return <></>; | |||
} | |||
|
|||
if (controller.session(policies)) { | |||
if (hasSessionForPolicies) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm does this migration to async maintain the same behavior? It seems on initial render it will be false and proceed now. I think we might need a loading state for the intermediate state, when the useEffect
hasn't been executed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you're right that this is technically not the exact same behaviour as the sync version. However, I think under a real world scenario it's very unlikely that users would ever run into the case where the loading state is observable. This is because when .connect()
is called, it's highly unlikely that the host app would somehow also be blocking the wasm module. After all, .connect()
is likely their first function call before doing anything real. This means that despite being async
, the hasSessionForPolicies
state would instantaneously be set to its desired value.
That said, I can certainly add a loading state. It's just that given the unlikeliness of it being actually observable as discussed above, I'd go for something very primitive. I will test it by artificially delaying the wasm call.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Got conflicts. Rebasing now. |
cca72f8
to
6e47dcb
Compare
Rebased. |
this is also happening on dojo.js torii client |
Concurrent calls to the wasm module where at least one call borrows
CartridgeAccount
mutably causeswasm-bindgen
's runtime borrow checker to throw:This PR fixes it by:
CartridgeAccountWithMeta
type is now used for reading fixed values. This type is only ever borrowed immutably, so concurrent accesses are fine.controller
value with a Promise-backedWasmMutex
, and changing all entrypoint signatures to use&self
instead of&mut self
.Note
Using a mutex for all calls, as implemented in this PR, is an overkill. A more ideal implementation would be something like a
RwLock
such that concurrent reads are still allowed.